package com.wfs.suanfa.cas;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.LongAdder;

/**
 * @author: wfs
 * @Date: 2020/7/21 15:53
 * @Description:
 */
public class AtomicIntegerTest {
    AtomicInteger a=new AtomicInteger(0);
   static volatile AtomicInteger b=new AtomicInteger(0);

    void  m(){
        for (int i=1;i<=10000;i++){
            a.incrementAndGet();
        }
    }


    public static void main(String[] args) {
        AtomicIntegerTest test=new AtomicIntegerTest();
        List<Thread> threads=new ArrayList<>();

        for (int i = 0; i < 10; i++) {
            threads.add(new Thread(test::m,"thread-"+i));
        }
        threads.forEach(t->t.start());


        for (int i=0;i<=100;i++){
            new Thread(new Runnable() {
                @Override
                public void run() {
                    b.incrementAndGet();
                }
            }).start();
        }
        System.out.println(b.get());
        try {
            Thread.sleep(1000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(test.a.get());
    }
}
